function HandleSearchParcel(gui, item, options) {
  this._gui = gui;
  this._item = item;
  this._options = options;
  this._popupBox = new PopupBox();
  
  this._callbackFunc = (options && options.callbackFunc) ? options.callbackFunc : function() {};
  this._query = (options && options.query) ? options.query : '1=1';
  
  this._createElements();
}

HandleSearchParcel.prototype._createElements = function() {
  var _self = this;
  this._gui.cfrom.value = (this._gui.cfrom) ? SimpleDate.format(this._gui.cfrom) : '';
  this._gui.cfrom.onclick = function() { var context = this;
                                                _self._changeDate.call(_self, this, _self._gui.cfrom, function(sd) { _self._gui.cfrom = sd; context.focus(); }, false);
                                                return false;
                                              };
  this._gui.cfrom.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                    if (code == 13) {
                                                      _self._callbackFunc.call(_self, _self._toString(_self._search), (_self._search.weddingDay) ? JSON.stringify(_self._search.weddingDay) : null, (_self._search.dateFrom) ? JSON.stringify(_self._search.dateFrom) : null, (_self._search.dateTo) ? JSON.stringify(_self._search.dateTo) : null, DOMUtils.findPos(this));
                                                    }
                                                  };
  this._gui.cto.value = (this._gui.cto) ? SimpleDate.format(this._gui.cto) : '';
  this._gui.cto.onclick = function() { var context = this;
                                              _self._changeDate.call(_self, this, _self._gui.cto, function(sd) { _self._gui.cto = sd; context.focus(); }, false);
                                              return false;
                                            };
  this._gui.cto.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                  if (code == 13) {
                                                    _self._callbackFunc.call(_self, _self._toString(_self._search), (_self._search.weddingDay) ? JSON.stringify(_self._search.weddingDay) : null, (_self._search.dateFrom) ? JSON.stringify(_self._search.dateFrom) : null, (_self._search.dateTo) ? JSON.stringify(_self._search.dateTo) : null, DOMUtils.findPos(this));
                                                  }
                                                };  
  
  this._gui.mailNo.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                              if (code == 13) {
                                                _self._callbackFunc(escape(((_self._gui.mailNo.value != '') ? 'd.code LIKE \'%' + _self._gui.mailNo.value + '%\'' : '1=1') + ' AND ' + ((_self._gui.customerNo.value != '') ? 'd2.customerId = \'' + _self._gui.customerNo.value + '\'' : '1 = 1')));
                                              }
                                            };
  this._gui.mailNo.onkeyup = function() { if (_self._gui.mailNo.value.length == 0) {
                                              _self._popupBox._close();
                                            } else {
                                              var div = document.createElement('div');
                                              var pos1 = DOMUtils.findPos(_self._gui.mailNo);
                                              var pos = [pos1[0], pos1[1] + 82];
                                              var query = "SELECT DISTINCT d.code FROM ns_Produce as d WHERE " + _self._query + "AND " + '((d.code LIKE \'%' + _self._gui.mailNo.value + '%\'))' + " ";
                                              MiscUtils.dialog(_self._popupBox, pos, div, null, null, {pop: true});
                                              new DialogSearchResult(div, _self._gui.mailNo, { query: query, popupBox: _self._popupBox, callbackFunc: function() { _self._createElements(); }, php: Constant.FACTORY + '/customphp/mysqlcustom.php', width: 110 });
                                            }
                                          };
  this._gui.customerNo.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                  if (code == 13) {
                                                    _self._callbackFunc(escape(((_self._gui.mailNo.value != '') ? 'd.code LIKE \'%' + _self._gui.mailNo.value + '%\'' : '1=1') + ' AND ' + ((_self._gui.customerNo.value != '') ? 'd2.customerId = \'' + _self._gui.customerNo.value + '\'' : '1 = 1')));
                                                  }
                                                };
  this._gui.customerNo.onkeyup = function() { if (_self._gui.customerNo.value.length == 0) {
                                                  _self._popupBox._close();
                                                } else {
                                                  var div = document.createElement('div');
                                                  var pos1 = DOMUtils.findPos(_self._gui.customerNo);
                                                  var pos = [pos1[0] + 1, pos1[1] + 82];
                                                  var query = "SELECT DISTINCT d2.customerId as customerId FROM ns_Produce as d LEFT JOIN ns_produce AS d2 ON d.trackId = d2.parent_trackId WHERE " + _self._query + " AND " + '((d2.customerId LIKE \'%' + _self._gui.customerNo.value + '%\'))' + " ";
                                                  MiscUtils.dialog(_self._popupBox, pos, div, null, null, {pop: true});
                                                  new DialogSearchResult(div, _self._gui.customerNo, { query: query, popupBox: _self._popupBox, callbackFunc: function() { _self._createElements();}, php: Constant.FACTORY + '/customphp/mysqlcustom.php', width: 110});
                                                }
                                              };

  this._gui.button.onclick = function() { _self._callbackFunc(escape(((_self._gui.mailNo.value != '') ? 'd.code LIKE \'%' + _self._gui.mailNo.value + '%\'' : '1=1') + ' AND ' + ((_self._gui.customerNo.value != '') ? 'd2.customerId = \'' + _self._gui.customerNo.value + '\'' : '1 = 1'))); };
};

HandleSearchParcel.prototype._changeDate = function(label, currentDate, onChangeFunc, showTime) {
  var _self = this;
  this._wContainer = document.createElement('div');
  this._wContainer.style.left = DOMUtils.findPos(label)[0] + 'px';
  this._wContainer.style.top = DOMUtils.findPos(label)[1] + 'px';
  this._popupBox._open(this._wContainer, { pos: DOMUtils.findPos(label) });
  
  var ds = new DateSelect(currentDate, null, { container: this._wContainer, showTime: showTime });
  ds._selectFunc = function(sd) { _self._selectDate.call(_self, sd, label, onChangeFunc, showTime); };
};

HandleSearchParcel.prototype._selectDate = function(sd, label, onChangeFunc, showTime) {
  
  onChangeFunc(sd);
  this._showDate(sd, label, showTime);
  this._popupBox._close();
};

HandleSearchParcel.prototype._showDate = function(sd, label, showTime) {
  if (sd) { 
    label.value = SimpleDate.format(sd, showTime);
  } else {
    label.value = '';
  }
};
